package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.service.ItemService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DubboService
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemMapper tbItemMapper;

    @Override
    public int insert(TbItem s) {
        int i = tbItemMapper.insertSelective(s);
        return i;
    }

    @Override
    public TbItem selectById(Long itemId) {

        return tbItemMapper.selectByPrimaryKey(itemId);
    }

    @Override
    public void minusNum(Long itemId, Integer num) {
        TbItem tbItem = tbItemMapper.selectByPrimaryKey(itemId);
        if (tbItem.getStockCount() > 0) {
            tbItem.setStockCount(tbItem.getStockCount() - num);
            tbItemMapper.updateByPrimaryKeySelective(tbItem);
        }
    }
}
